package com.itheima.app.controller;

import com.itheima.app.manager.SettingsManager;
import com.itheima.app.manager.UserManager;
import com.itheima.domain.db.Notification;
import com.itheima.domain.db.User;
import com.itheima.domain.vo.PageBeanVo;
import com.itheima.domain.vo.SettingVo;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
public class SettingsController {

    @Autowired
    private UserManager userManager;
    /**
     * 查询用户的通知信息
     */
    @GetMapping("/users/settings")
    public SettingVo findSettings(){
        return userManager.findSettings();
    }



    @Autowired
    private SettingsManager settingsManager;
    /**
     * 保存或者修改陌生人问题
     * @return
     */
    @PostMapping("/users/questions")
    public SettingVo saveOrUpdateQuestion(@RequestBody Map map){
        //获得输入的文本数据
        String content = map.get("content").toString();
        //保存或者修改
        return settingsManager.saveOrUpdateQuestion(content);
    }

    /**
     * 保存或者修改通知设置
     * @return
     */
    @PostMapping("/users/notifications/setting")
    public SettingVo saveOrUpdateNotifications(@RequestBody Notification notification){

        //保存或者修改
        return settingsManager.saveOrUpdateNotifications(notification);
    }




    /**
     * 查询黑名单数据
     * @return
     */
    @GetMapping("/users/blacklist")
    public PageBeanVo findBlackList(
            @RequestParam(defaultValue = "1") Integer page ,
            @RequestParam(defaultValue = "5") Integer pageSize){

        //查询黑名单数据
        return settingsManager.findBlackList(page , pageSize);
    }


    /**
     * 删除黑名单用户信息
     * @return
     */
    @DeleteMapping("/users/blacklist/{blackUserId}")
    public Map deleteBlackUser(@PathVariable Long blackUserId){
        settingsManager.deleteBlackUser(blackUserId);
        return  null;
    }
}
